/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package project;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author jon
 */
public class Views {
    private int client_number;
    private int property_number;
    private String date_of_view;
    private String comments;

    public Views(int client_number, int property_number, String date_of_view, String comments) {
        this.client_number = client_number;
        this.property_number = property_number;
        this.date_of_view = date_of_view;
        this.comments = comments;
    }


    
    /**
     * @return the client_number
     */
    public int getClient_number() {
        return client_number;
    }

    /**
     * @param client_number the client_number to set
     */
    public void setClient_number(int client_number) {
        this.client_number = client_number;
    }

    /**
     * @return the property_number
     */
    public int getProperty_number() {
        return property_number;
    }

    /**
     * @param property_number the property_number to set
     */
    public void setProperty_number(int property_number) {
        this.property_number = property_number;
    }

    /**
     * @return the date_of_view
     */
    public String getDate_of_view() {
        return date_of_view;
    }

    /**
     * @param date_of_view the date_of_view to set
     */
    public void setDate_of_view(String date_of_view) {
        this.date_of_view = date_of_view;
    }

    /**
     * @return the comments
     */
    public String getComments() {
        return comments;
    }

    /**
     * @param comments the comments to set
     */
    public void setComments(String comments) {
        this.comments = comments;
    }

    public void insert()
    {
        try
        {
            String host = "jdbc:oracle:thin:@localhost:1521:xe";
            String username = "jon";
            String password = "chaosecco";
            String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);

            Connection connection = DriverManager.getConnection(host,
                    username, password);
            System.out.print("Connected successfully.");
            String insertQuery = "INSERT INTO VIEWS(" +
                    "client_number, " +
                    "property_number, "  +
                    "date_of_view, " +
                    "comments)" +
                    "VALUES(?, ?, ?, ?)";
            PreparedStatement ps = connection.prepareStatement(insertQuery);
            ps.setInt(1, client_number);
            ps.setInt(2, property_number);
            ps.setString(3, date_of_view);
            ps.setString(4, comments);
            ps.executeUpdate();

            connection.close();
        }

        catch (SQLException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }

        catch(ClassNotFoundException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }
    }

}
